<script setup lang="ts">
import { useHomeStore } from '@/store'
import HomePanel from './HomePanel.vue'
import { storeToRefs } from 'pinia'
import { ref } from 'vue'
import { useObserver } from '@/hooks'

const homeStore = useHomeStore()
const { newGoodsList } = storeToRefs(homeStore)
const { getNewGoodsList } = homeStore
const target = ref<HTMLElement | null>(null)
useObserver(target, getNewGoodsList)
</script>

<template>
  <div class="home-new" ref="target">
    <HomePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
      <template #right><XtxMore path="/" /></template>
      <ul class="goods-list" v-if="newGoodsList.length > 0">
        <li v-for="item in newGoodsList" :key="item.id">
          <RouterLink :to="`/goods/${item.id}`">
            <img :src="item.picture" />
            <p class="name ellipsis">{{ item.name }}</p>
            <p class="price">&yen;{{ item.price }}</p>
          </RouterLink>
        </li>
      </ul>
      <!-- 骨架屏 -->
      <ul class="goods-list" v-else>
        <li v-for="item in 4" :key="item">
          <XtxSkeleton :width="306" :height="406" />
        </li>
      </ul>
    </HomePanel>
  </div>
</template>

<style lang="less" scoped>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;

  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();

    img {
      width: 306px;
      height: 306px;
    }

    p {
      padding: 12px 30px 0 30px;
      font-size: 22px;
      text-align: center;
    }

    .price {
      color: @priceColor;
    }
  }
}
</style>
